/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.service.impl;


import ecommerce.dao.BookDao;
import ecommerce.dao.CategoryDao;
import ecommerce.dao.CustomerDao;
import ecommerce.dao.ItemDao;
import ecommerce.dao.OrderDao;
import ecommerce.dao.PaymentDao;
import ecommerce.model.Book;
import ecommerce.model.Category;
import ecommerce.model.Customer;
import ecommerce.model.Item;
import ecommerce.model.Order;
import ecommerce.model.Payment;
import ecommerce.service.EcommerceService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Hadi
 */
@Service ("bookService")
@Transactional(readOnly=true) // secara default, semua method readOnly= true
public class EcommerceServiceImpl implements EcommerceService{

    @Autowired private BookDao bookDao;
    @Autowired private CategoryDao categoryDao;
    @Autowired private ItemDao itemDao;
    @Autowired private OrderDao orderDao;
    @Autowired private CustomerDao customerDao;
    @Autowired private PaymentDao paymentDao;

    @Transactional(readOnly=false)
    public void save(Book c) {
        bookDao.save(c);
    }

    @Transactional(readOnly=false)
    public void delete(Book c) {
        bookDao.delete(c);
    }

    public Book getBook(Long id) {
        return bookDao.findById(id);
    }

    public Item getItem(Long id) {
        return itemDao.findById(id);
    }

    public Customer getCustomer(Long id) {
        return customerDao.findById(id);
    }
    public Order getOrder(Long id) {
        return orderDao.findById(id);
    }

    public List<Book> getBooks() {
        return bookDao.getAll();
    }

    @Transactional(readOnly=false)
    public void save(Category c) {
        categoryDao.save(c);
    }

    @Transactional(readOnly=false)
    public void save(Item item) {
        itemDao.save(item);
    }

    @Transactional(readOnly=false)
    public void save(Order order) {
        orderDao.save(order);
    }

    @Transactional(readOnly=false)
    public void save(Customer customer) {
        customerDao.save(customer);
    }

    public Payment getPayment(Long id) {
        return paymentDao.findById(id);
    }

    @Transactional(readOnly=false)
    public void save(Payment p) {
        paymentDao.save(p);
    }





}
